﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using CE.Database;

/// <summary>
/// Summary description for FleetBrokerPremiumDB
/// </summary>
namespace CE.CarInsurance
{
    public class FleetBrokerPremiumDB
    {
        public Int64 Insert(FleetBrokerPremium fleetbrokerpremium)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocFleetBrokerPremiumInsertUpdateSingleItem";
            SortedList _sPara = new SortedList();
            #region Parameter
            _sPara.Add("@FleetBrokerPremiumId", fleetbrokerpremium.FleetBrokerPremiumId);
            _sPara.Add("@CXBrokerProviderId", fleetbrokerpremium.CXBrokerProviderId);
            _sPara.Add("@ProviderCoverTypeId", fleetbrokerpremium.ProviderCoverTypeId);
            _sPara.Add("@FleetCarId", fleetbrokerpremium.FleetCarId);
            _sPara.Add("@CompanyId", fleetbrokerpremium.CompanyId);
            _sPara.Add("@AgentId", fleetbrokerpremium.AgentId);
            _sPara.Add("@RefCEUserId", fleetbrokerpremium.RefCEUserId);
            _sPara.Add("@Premium", fleetbrokerpremium.Premium);
            _sPara.Add("@SelectedStatus", fleetbrokerpremium.SelectedStatus);
            _sPara.Add("@Package", fleetbrokerpremium.Package);
            _sPara.Add("@WorkShop", fleetbrokerpremium.WorkShop);
            _sPara.Add("@ProductType", fleetbrokerpremium.ProductType);
            _sPara.Add("@DiscountPercentage", fleetbrokerpremium.DiscountPercentage);
            _sPara.Add("@FinalAnnualPremium", fleetbrokerpremium.FinalAnnualPremium);
            _sPara.Add("@FInfo1", fleetbrokerpremium.FinalAnnualPremiumNoDisc);
            _sPara.Add("@AnnualPremium", fleetbrokerpremium.AnnualPremium);
            _sPara.Add("@OriginalPremiumWD", fleetbrokerpremium.OriginalPremiumWD); // Original Premium with discount
            _sPara.Add("@OriginalPremiumWOD", fleetbrokerpremium.OriginalPremiumWOD); // Original Premium without discount
            _sPara.Add("@ApprovedPremium", fleetbrokerpremium.ApprovedPremium); // Approved Premium
            _sPara.Add("@TescoAmount", fleetbrokerpremium.TescoAmount); // Tesco Amount
            _sPara.Add("@TescoSelect", fleetbrokerpremium.TescoSelect); // Tesco Selection
            _sPara.Add("@Approved", fleetbrokerpremium.Approved); // Approved 

            if (fleetbrokerpremium.PromotionPrice > 0)
            {
                _sPara.Add("@PromotionPrice", fleetbrokerpremium.PromotionPrice);
            }

            if (fleetbrokerpremium.MonthlyInstallment > 0)
            {
                _sPara.Add("@MonthlyInstallment", fleetbrokerpremium.MonthlyInstallment);
            }

            if (fleetbrokerpremium.TotalVMI > 0)
            {
                _sPara.Add("@TotalVMI", fleetbrokerpremium.TotalVMI);
            }

            if (fleetbrokerpremium.TotalCMI > 0)
            {
                _sPara.Add("@TotalCMI", fleetbrokerpremium.TotalCMI);
            }

            _sPara.Add("@IsIncludeCMI", fleetbrokerpremium.IsIncludeCMI);

            if (fleetbrokerpremium.TPPD != string.Empty)
            {
                _sPara.Add("@TPPD", fleetbrokerpremium.TPPD);
            }

            if (fleetbrokerpremium.TPBIP != string.Empty)
            {
                _sPara.Add("@TPBIP", fleetbrokerpremium.TPBIP);
            }

            if (fleetbrokerpremium.TPBIA != string.Empty)
            {
                _sPara.Add("@TPBIA", fleetbrokerpremium.TPBIA);
            }

            if (fleetbrokerpremium.DEC != string.Empty)
            {
                _sPara.Add("@DEC", fleetbrokerpremium.DEC);
            }

            if (fleetbrokerpremium.SumInsured > 0)
            {
                _sPara.Add("@SumInsured", fleetbrokerpremium.SumInsured);
            }

            if (fleetbrokerpremium.FireTheft != string.Empty)
            {
                _sPara.Add("@FireTheft", fleetbrokerpremium.FireTheft);
            }

            if (fleetbrokerpremium.OwnDamage != string.Empty)
            {
                _sPara.Add("@OwnDamage", fleetbrokerpremium.OwnDamage);
            }

            if (fleetbrokerpremium.PADriver != string.Empty)
            {
                _sPara.Add("@PADriver", fleetbrokerpremium.PADriver);
            }

            if (fleetbrokerpremium.PAPassenger != string.Empty)
            {
                _sPara.Add("@PAPassenger", fleetbrokerpremium.PAPassenger);
            }

            if (fleetbrokerpremium.MedicalExpense != string.Empty)
            {
                _sPara.Add("@MedicalExpense", fleetbrokerpremium.MedicalExpense);
            }

            if (fleetbrokerpremium.BailBound != string.Empty)
            {
                _sPara.Add("@BailBond", fleetbrokerpremium.BailBound);
            }

            if (fleetbrokerpremium.Info1 != string.Empty)
            {
                _sPara.Add("@Info1", fleetbrokerpremium.Info1);
            }

            if (fleetbrokerpremium.Info2 != string.Empty)
            {
                _sPara.Add("@Info2", fleetbrokerpremium.Info2);
            }

            if (fleetbrokerpremium.Info2 != string.Empty)
            {
                _sPara.Add("@Info3", fleetbrokerpremium.Info3);
            }

            if (fleetbrokerpremium.Info4 != string.Empty)
            {
                _sPara.Add("@Info4", fleetbrokerpremium.Info4);
            }

            if (fleetbrokerpremium.Info5 != string.Empty)
            {
                _sPara.Add("@Info5", fleetbrokerpremium.Info5);
            }

            if (fleetbrokerpremium.Info6 != string.Empty)
            {
                _sPara.Add("@Info6", fleetbrokerpremium.Info6);
            }

            if (fleetbrokerpremium.Info7 != string.Empty)
            {
                _sPara.Add("@Info7", fleetbrokerpremium.Info7);
            }

            if (fleetbrokerpremium.Info8 != string.Empty)
            {
                _sPara.Add("@Info8", fleetbrokerpremium.Info8);
            }

            if (fleetbrokerpremium.Info9 != string.Empty)
            {
                _sPara.Add("@Info9", fleetbrokerpremium.Info9);
            }

            if (fleetbrokerpremium.Info10 != string.Empty)
            {
                _sPara.Add("@Info10", fleetbrokerpremium.Info10);
            }

            _sPara.Add("@PaymentOption", fleetbrokerpremium.PaymentOption);
            _sPara.Add("@NoofInstallment", fleetbrokerpremium.NoofInstallment);
            _sPara.Add("@Bank", fleetbrokerpremium.Bank);
            _sPara.Add("@FAPremiumWD", fleetbrokerpremium.FinalAnnualPremiumWD);
            _sPara.Add("@IPFAPremiumWD", fleetbrokerpremium.IPFinalAnnualPremiumWD);
            _sPara.Add("@InsAmountWD", fleetbrokerpremium.InstallmentAmountWD);
            _sPara.Add("@LastInsAmountWD", fleetbrokerpremium.LastInstallmentAmountWD);
            _sPara.Add("@FAPremiumWOD", fleetbrokerpremium.FinalAnnualPremiumWOD);
            _sPara.Add("@IPFAPremiumWOD", fleetbrokerpremium.IPFinalAnnualPremiumWOD);
            _sPara.Add("@InsAmountWOD", fleetbrokerpremium.InstallmentAmountWOD);
            _sPara.Add("@LastInsAmountWOD", fleetbrokerpremium.LastInstallmentAmountWOD);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);
            return _result;
        }

        public FleetBrokerPremium GetBrokerPremiumSingleItem(Int64 FleetBrokerPremiumId, Int64 CXBrokerProviderId, Int64 FleetCarId, Int64 CompanyId, string ProductType)
        {
            FleetBrokerPremium _mybrokerpremium = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocFleetBrokerPremiumSelectSingleItemByPremiumId";

            SortedList _spara = new SortedList();
            _spara.Add("@FleetBrokerPremiumId", FleetBrokerPremiumId);
            _spara.Add("@CXBrokerProviderId", CXBrokerProviderId);
            _spara.Add("@FleetCarId", FleetCarId);
            _spara.Add("@CompanyId", CompanyId);
            _spara.Add("@ProductType", ProductType);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _mybrokerpremium = new FleetBrokerPremium();
                    _mybrokerpremium = FillDataRecord(_dt, 0);
                }
            }
            return _mybrokerpremium;
        }

        private FleetBrokerPremium FillDataRecord(DataTable myDataTable, int RowId)
        {
            FleetBrokerPremium myBrokerPremium = new FleetBrokerPremium();
            myBrokerPremium.FleetBrokerPremiumId = Convert.ToInt64(myDataTable.Rows[RowId]["FleetBrokerPremiumId"].ToString());
            myBrokerPremium.CXBrokerProviderId = Convert.ToInt64(myDataTable.Rows[RowId]["CXBrokerProviderId"].ToString());
            myBrokerPremium.ProviderCoverTypeId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCoverTypeId"].ToString());
            myBrokerPremium.FleetCarId = Convert.ToInt64(myDataTable.Rows[RowId]["FleetCarId"].ToString());
            myBrokerPremium.CompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["CompanyId"].ToString());
            myBrokerPremium.AgentId = Convert.ToInt64(myDataTable.Rows[RowId]["AgentId"].ToString());
            myBrokerPremium.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myBrokerPremium.Premium = Convert.ToSingle(myDataTable.Rows[RowId]["Premium"].ToString());

            myBrokerPremium.SelectedStatus = Convert.ToBoolean(myDataTable.Rows[RowId]["SelectedStatus"].ToString());
            myBrokerPremium.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());
            myBrokerPremium.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            myBrokerPremium.Package = myDataTable.Rows[RowId]["Package"].ToString();
            myBrokerPremium.WorkShop = myDataTable.Rows[RowId]["WorkShop"].ToString();
            myBrokerPremium.ProductType = myDataTable.Rows[RowId]["ProductType"].ToString();

            myBrokerPremium.DiscountPercentage = Convert.ToInt16(myDataTable.Rows[RowId]["DiscountPercentage"].ToString());
            if (myDataTable.Rows[RowId]["FinalAnnualPremium"] != DBNull.Value)
            {
                myBrokerPremium.FinalAnnualPremium = Convert.ToSingle(myDataTable.Rows[RowId]["FinalAnnualPremium"].ToString());
            }
            if (myDataTable.Rows[RowId]["FInfo1"] != DBNull.Value)
            {
                myBrokerPremium.FinalAnnualPremiumNoDisc = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());
            }
            if (myDataTable.Rows[RowId]["AnnualPremium"] != DBNull.Value)
            {
                myBrokerPremium.AnnualPremium = Convert.ToSingle(myDataTable.Rows[RowId]["AnnualPremium"].ToString());
            }

            if (myDataTable.Rows[RowId]["PromotionPrice"] != DBNull.Value)
            {
                myBrokerPremium.PromotionPrice = Convert.ToSingle(myDataTable.Rows[RowId]["PromotionPrice"].ToString());
            }

            if (myDataTable.Rows[RowId]["MonthlyInstallment"] != DBNull.Value)
            {
                myBrokerPremium.MonthlyInstallment = Convert.ToSingle(myDataTable.Rows[RowId]["MonthlyInstallment"].ToString());
            }

            if (myDataTable.Rows[RowId]["TotalVMI"] != DBNull.Value)
            {
                myBrokerPremium.TotalVMI = Convert.ToSingle(myDataTable.Rows[RowId]["TotalVMI"].ToString());
            }

            if (myDataTable.Rows[RowId]["TotalCMI"] != DBNull.Value)
            {
                myBrokerPremium.TotalCMI = Convert.ToSingle(myDataTable.Rows[RowId]["TotalCMI"].ToString());
            }

            if (myDataTable.Rows[RowId]["IsIncludeCMI"] != DBNull.Value)
            {
                myBrokerPremium.IsIncludeCMI = Convert.ToBoolean(myDataTable.Rows[RowId]["IsIncludeCMI"].ToString());
            }

            if (myDataTable.Rows[RowId]["TPPD"] != DBNull.Value)
            {
                myBrokerPremium.TPPD = myDataTable.Rows[RowId]["TPPD"].ToString();
            }

            if (myDataTable.Rows[RowId]["TPBIP"] != DBNull.Value)
            {
                myBrokerPremium.TPBIP = myDataTable.Rows[RowId]["TPBIP"].ToString();
            }

            if (myDataTable.Rows[RowId]["TPBIA"] != DBNull.Value)
            {
                myBrokerPremium.TPBIA = myDataTable.Rows[RowId]["TPBIA"].ToString();
            }

            if (myDataTable.Rows[RowId]["DEC"] != DBNull.Value)
            {
                myBrokerPremium.DEC = myDataTable.Rows[RowId]["DEC"].ToString();
            }

            if (myDataTable.Rows[RowId]["SumInsured"] != DBNull.Value)
            {
                myBrokerPremium.SumInsured = Convert.ToInt32(myDataTable.Rows[RowId]["SumInsured"].ToString());
            }

            if (myDataTable.Rows[RowId]["FireTheft"] != DBNull.Value)
            {
                myBrokerPremium.FireTheft = myDataTable.Rows[RowId]["FireTheft"].ToString();
            }

            if (myDataTable.Rows[RowId]["OwnDamage"] != DBNull.Value)
            {
                myBrokerPremium.OwnDamage = myDataTable.Rows[RowId]["OwnDamage"].ToString();
            }

            if (myDataTable.Rows[RowId]["PADriver"] != DBNull.Value)
            {
                myBrokerPremium.PADriver = myDataTable.Rows[RowId]["PADriver"].ToString();
            }

            if (myDataTable.Rows[RowId]["PAPassenger"] != DBNull.Value)
            {
                myBrokerPremium.PAPassenger = myDataTable.Rows[RowId]["PAPassenger"].ToString();
            }

            if (myDataTable.Rows[RowId]["MedicalExpense"] != DBNull.Value)
            {
                myBrokerPremium.MedicalExpense = myDataTable.Rows[RowId]["MedicalExpense"].ToString();
            }

            if (myDataTable.Rows[RowId]["BailBond"] != DBNull.Value)
            {
                myBrokerPremium.BailBound = myDataTable.Rows[RowId]["BailBond"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info1"] != DBNull.Value)
            {
                myBrokerPremium.Info1 = myDataTable.Rows[RowId]["Info1"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info2"] != DBNull.Value)
            {
                myBrokerPremium.Info2 = myDataTable.Rows[RowId]["Info2"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info3"] != DBNull.Value)
            {
                myBrokerPremium.Info3 = myDataTable.Rows[RowId]["Info3"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info4"] != DBNull.Value)
            {
                myBrokerPremium.Info4 = myDataTable.Rows[RowId]["Info4"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info5"] != DBNull.Value)
            {
                myBrokerPremium.Info5 = myDataTable.Rows[RowId]["Info5"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info6"] != DBNull.Value)
            {
                myBrokerPremium.Info6 = myDataTable.Rows[RowId]["Info6"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info7"] != DBNull.Value)
            {
                myBrokerPremium.Info7 = myDataTable.Rows[RowId]["Info7"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info8"] != DBNull.Value)
            {
                myBrokerPremium.Info8 = myDataTable.Rows[RowId]["Info8"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info9"] != DBNull.Value)
            {
                myBrokerPremium.Info9 = myDataTable.Rows[RowId]["Info9"].ToString();
            }

            if (myDataTable.Rows[RowId]["Info10"] != DBNull.Value)
            {
                myBrokerPremium.Info10 = myDataTable.Rows[RowId]["Info10"].ToString();
            }

            if (myDataTable.Rows[RowId]["PaymentOption"] != DBNull.Value)
            {
                myBrokerPremium.PaymentOption = myDataTable.Rows[RowId]["PaymentOption"].ToString();
            }
            else
            {
                myBrokerPremium.PaymentOption = "FP";
            }

            if (myDataTable.Rows[RowId]["NoofInstallment"] != DBNull.Value)
            {
                Int32 NoofInstallment = 0;
                if (!Int32.TryParse(myDataTable.Rows[RowId]["NoofInstallment"].ToString(), out NoofInstallment))
                {
                    NoofInstallment = 0;
                }
                myBrokerPremium.NoofInstallment = NoofInstallment;
            }

            if (myDataTable.Rows[RowId]["Bank"] != DBNull.Value)
            {
                string Bank = myDataTable.Rows[RowId]["Bank"].ToString();
                myBrokerPremium.Bank = Bank;
            }

            if (myDataTable.Rows[RowId]["FinalAnnualPremiumWD"] != DBNull.Value)
            {
                myBrokerPremium.FinalAnnualPremiumWD = Convert.ToSingle(myDataTable.Rows[RowId]["FinalAnnualPremiumWD"].ToString());
            }

            if (myDataTable.Rows[RowId]["IPFinalAnnualPremiumWD"] != DBNull.Value)
            {
                float IPFinalAnnualPremiumWD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["IPFinalAnnualPremiumWD"].ToString(), out IPFinalAnnualPremiumWD))
                {
                    IPFinalAnnualPremiumWD = 0.0f;
                }
                myBrokerPremium.IPFinalAnnualPremiumWD = IPFinalAnnualPremiumWD;
            }

            if (myDataTable.Rows[RowId]["InstallmentAmountWD"] != DBNull.Value)
            {
                float InstallmentAmountWD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["InstallmentAmountWD"].ToString(), out InstallmentAmountWD))
                {
                    InstallmentAmountWD = 0.0f;
                }
                myBrokerPremium.InstallmentAmountWD = InstallmentAmountWD;
            }

            if (myDataTable.Rows[RowId]["LastInstallmentAmountWD"] != DBNull.Value)
            {
                float LastInstallmentAmountWD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["LastInstallmentAmountWD"].ToString(), out LastInstallmentAmountWD))
                {
                    LastInstallmentAmountWD = 0.0f;
                }
                myBrokerPremium.LastInstallmentAmountWD = LastInstallmentAmountWD;
            }

            if (myDataTable.Rows[RowId]["FinalAnnualPremiumWOD"] != DBNull.Value)
            {
                myBrokerPremium.FinalAnnualPremiumWOD = Convert.ToSingle(myDataTable.Rows[RowId]["FinalAnnualPremiumWOD"].ToString());
            }

            if (myDataTable.Rows[RowId]["IPFinalAnnualPremiumWOD"] != DBNull.Value)
            {
                float IPFinalAnnualPremiumWOD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["IPFinalAnnualPremiumWOD"].ToString(), out IPFinalAnnualPremiumWOD))
                {
                    IPFinalAnnualPremiumWOD = 0.0f;
                }
                myBrokerPremium.IPFinalAnnualPremiumWOD = IPFinalAnnualPremiumWOD;
            }

            if (myDataTable.Rows[RowId]["InstallmentAmountWOD"] != DBNull.Value)
            {
                float InstallmentAmountWOD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["InstallmentAmountWOD"].ToString(), out InstallmentAmountWOD))
                {
                    InstallmentAmountWOD = 0.0f;
                }
                myBrokerPremium.InstallmentAmountWOD = InstallmentAmountWOD;
            }

            if (myDataTable.Rows[RowId]["LastInstallmentAmountWOD"] != DBNull.Value)
            {
                float LastInstallmentAmountWOD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["LastInstallmentAmountWOD"].ToString(), out LastInstallmentAmountWOD))
                {
                    LastInstallmentAmountWOD = 0.0f;
                }
                myBrokerPremium.LastInstallmentAmountWOD = LastInstallmentAmountWOD;
            }

            if (myDataTable.Rows[RowId]["OriginalPremiumWD"] != DBNull.Value)
            {
                float OriginalPremiumWD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["OriginalPremiumWD"].ToString(), out OriginalPremiumWD))
                {
                    OriginalPremiumWD = 0.0f;
                }
                myBrokerPremium.OriginalPremiumWD = OriginalPremiumWD;
            }
            else
            {
                myBrokerPremium.OriginalPremiumWD = myBrokerPremium.FinalAnnualPremium;
            }

            if (myDataTable.Rows[RowId]["OriginalPremiumWOD"] != DBNull.Value)
            {
                float OriginalPremiumWOD = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["OriginalPremiumWOD"].ToString(), out OriginalPremiumWOD))
                {
                    OriginalPremiumWOD = 0.0f;
                }
                myBrokerPremium.OriginalPremiumWOD = OriginalPremiumWOD;
            }
            else
            {
                myBrokerPremium.OriginalPremiumWOD = myBrokerPremium.FinalAnnualPremiumNoDisc;
            }

            if (myDataTable.Rows[RowId]["ApprovedPremium"] != DBNull.Value)
            {
                float ApprovedPremium = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["ApprovedPremium"].ToString(), out ApprovedPremium))
                {
                    ApprovedPremium = 0.0f;
                }
                myBrokerPremium.ApprovedPremium = ApprovedPremium;
            }
            else
            {
                myBrokerPremium.ApprovedPremium = myBrokerPremium.FinalAnnualPremium;
            }

            if (myDataTable.Rows[RowId]["TescoAmount"] != DBNull.Value)
            {
                float TescoAmount = 0.0f;
                if (!float.TryParse(myDataTable.Rows[RowId]["TescoAmount"].ToString(), out TescoAmount))
                {
                    TescoAmount = 0.0f;
                }
                myBrokerPremium.TescoAmount = TescoAmount;
            }
            else
            {
                myBrokerPremium.TescoAmount = 0.0f;
            }

            if (myDataTable.Rows[RowId]["TescoSelect"] != DBNull.Value)
            {
                Int16 TescoSelect = 0;
                if (!Int16.TryParse(myDataTable.Rows[RowId]["TescoSelect"].ToString(), out TescoSelect))
                {
                    TescoSelect = 0;
                }
                myBrokerPremium.TescoSelect = TescoSelect;
            }
            else
            {
                myBrokerPremium.TescoSelect = 0;
            }

            if (myDataTable.Rows[RowId]["Approved"] != DBNull.Value)
            {
                Int16 Approved = 0;
                if (!Int16.TryParse(myDataTable.Rows[RowId]["Approved"].ToString(), out Approved))
                {
                    Approved = 0;
                }
                myBrokerPremium.Approved = Approved;
            }
            else
            {
                myBrokerPremium.Approved = 0;
            }

            return myBrokerPremium;
        }

        public Int64 SaveQuotationEmail(Int64 CompanyId, string Email, Int64 RefCEUserId, Int16 QuoteCount, Int16 SendType)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocFleetBrokerPremiumQuotationEmailInsertUpdateSingleItem";
            SortedList _sPara = new SortedList();
            _sPara.Add("@CompanyId", CompanyId);
            _sPara.Add("@Email", Email);
            _sPara.Add("@RefCEUserId", RefCEUserId);
            _sPara.Add("@QuoteCount", QuoteCount);
            _sPara.Add("@SendType", SendType);
            _result = _db.ExecuteSP(_spName, _sPara);
            return _result;
        }

        public string GetLastQuotationSendDate(Int64 CompanyId, Int16 SendType)
        {
            string _retValue = string.Empty;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocFleetBrokerPremiumQuotationEmailGetLastSendDate";

            SortedList _spara = new SortedList();
            _spara.Add("@CompanyId", CompanyId);
            _spara.Add("@SendType", SendType);
            object _objLastDate = _db.ExecuteScalarSP(_spName, _spara);
            if (_objLastDate != null)
            {
                _retValue = _objLastDate.ToString();
            }
            return _retValue;
        }

    }
}